package studentdemo.server;

import studentdemo.dao.OfferDao;
import studentdemo.dao.OfferDaoImpl;
import studentdemo.modul.Offer;
import java.util.List;

public class OfferService {
    private final OfferDao offerDao = new OfferDaoImpl();

    public boolean addOffer(Offer offer) {
        return offerDao.insertOffer(offer) > 0;
    }

    public boolean deleteOffer(String ocno, String oclno) {
        return offerDao.deleteOffer(ocno, oclno) > 0;
    }

    public List<Offer> getOffersByCourse(String ocno) {
        return offerDao.getOffersByCourse(ocno);
    }

    public List<Offer> getOffersByClass(String oclno) {
        return offerDao.getOffersByClass(oclno);
    }

    public List<Offer> getAllOffers() {
        return offerDao.getAllOffers();
    }

    public boolean isCourseOfferedToClass(String courseNo, String classNo) {
        List<Offer> offers = offerDao.getOffersByCourse(courseNo);
        for (Offer offer : offers) {
            if (offer.getOclno().equals(classNo)) {
                return true;
            }
        }
        return false;
    }
} 